/*
 * Manager.cpp
 *
 *  Created on: 2011/07/02
 *      Author: naoki
 */

#include "NTEngine/NTEngine.h"
#include "FileIO/src/ManagerImpl.h"

#include "Base/src/android_app.h"


namespace NTEngine {
namespace FileIO {
using namespace std;

ManagerImpl* gManagerImpl = 0;

void Manager::create(
	void* app,
	const char** archiveNames,
	int archiveNumber,
	AccessMode am
) {
	HARD_ASSERT( gManagerImpl == 0 );
	HARD_ASSERT( app );
	android_app* p = static_cast< android_app* >( app );
	gManagerImpl = NEW ManagerImpl( archiveNames, archiveNumber, am,
		p->activity->assetManager, p->activity->internalDataPath, p->activity->externalDataPath );
}

void Manager::destroy() {
	SAFE_DELETE( gManagerImpl );
}

Manager Manager::instance() {
	ASSERT( gManagerImpl && "FileIO Module hasn't started yet!" );
	return Manager();
}

void Manager::write(
	const char* filename,
	const char* data,
	int size
) {
	gManagerImpl->writeFile( filename, data, size );
}

string Manager::createListString() const {
	return gManagerImpl->createListString();
}

void Manager::setLimit( int warning, int error ){
	gManagerImpl->setLimit( warning, error );
}

void Manager::enableHaltOnError( bool f ){
	gManagerImpl->enableHaltOnError( f );
}

bool Manager::isExists( const char* path ) const {
	return gManagerImpl->isExists( path );
}

} //namespace FileIO
} //namespace NTEngine
